<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function addStu(){
				var stus = document.getElementById("stus");
				
				var firstDiv = stus.children[0];
				var div = firestDiv.cloneNode(true);
				div.style.display = "block";
				stus.appendChild(div);
			}
			function computeScore(){
				var stus = document.getElementById("stus");
				var num = stus.children.length;
				var sum = 0;
				for(i = 1; i < num ; i++){
					var score = Number(stus.children[i].children[1].value);
					
					sum += score;
				}
				var avgScore = sum/(num-1);
				
				document.getElementById("avg").value = avgScore;
				document.getElementById("num").value = num-1;
			}
		</script>
	</head>
	<body>
		<div>
			学生成绩录入：
			<hr >
		</div>
		平均:<input type="text" id="avg"/>
		人数:<input type="text" id="num"/>
		<hr >
		<div id="stus">
			<div style="display: none;">
				学生姓名：<input type="text" id="avg"/>
				学生成绩：<input type="text" name="" id="num" value="" />
			</div>
		</div>
		<hr >
		<input type="button" value="计算" onclick="computeScore()"/>
		<input type="button" value="添加" onclick="addStu()"/>
	</body>
</html>
